package br.com.felix.fwt.ui.javascript;

import java.io.PrintWriter;
import java.io.Serializable;

import br.com.felix.fwt.servlet.FelixWebToolkitServlet;
import br.com.felix.fwt.ui.Renderable;
import br.com.felix.fwt.ui.exception.ComponentRenderException;

/**
 * Used to declare a reference to an external js file.
 * */
public class ExternalJavascript implements Serializable, Renderable {

	private static final long serialVersionUID = 7542026438824340588L;

	private String path;
	
	public ExternalJavascript(){
		
	}
	
	public ExternalJavascript(String path){
		this.path = path;
	}
	
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		out.write("<script type=\"text/javascript\" src=\"");
		out.write(FelixWebToolkitServlet.getFwtContext().request.getContextPath());
		out.write(path);
		out.write("\"></script>");
	}

}
